package com.shareach.domain.common;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

public class Entity {
	/**
	 * 用户唯一标识
	 */
	@Id
	private Long id;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Transient
	private List<String> fieldExists;
	@Transient
	private List<String> fieldNoneExists;
	@Transient
	private Map<String, List<Object>> propInList;
	@Transient
	private Map<String[], String> regexMap;
	@Transient
	private List<Long> inOpreatorList;

	public List<Long> getInOpreatorList() {
		return inOpreatorList;
	}

	public void setInOpreatorSet(List<Long> inOpreatorList) {
		this.inOpreatorList = inOpreatorList;
	}

	public Map<String[], String> getRegexMap() {
		return regexMap;
	}

	public void setRegexMap(Map<String[], String> regexMap) {
		this.regexMap = regexMap;
	}

	public List<String> getFieldExists() {
		return fieldExists;
	}

	public void addFieldExists(String propName) {
		if (null == this.fieldExists) {
			this.fieldExists = Lists.newArrayList();
		}
		this.fieldExists.add(propName);
	}

	/**
	 * 
	 * @param key
	 * @param regex
	 */
	public void addRegexMap(String regex, String... key) {
		if (null == this.regexMap) {
			regexMap = new HashMap<String[], String>();
		}
		regexMap.put(key, regex);
	}

	public void setFieldExists(List<String> fieldExists) {
		this.fieldExists = fieldExists;
	}

	public List<String> getFieldNoneExists() {
		return fieldNoneExists;
	}

	public void addFieldNoneExists(String propName) {
		if (null == this.fieldNoneExists) {
			this.fieldNoneExists = Lists.newArrayList();
		}
		this.fieldNoneExists.add(propName);
	}

	public void setFieldNoneExists(List<String> fieldNoneExists) {
		this.fieldNoneExists = fieldNoneExists;
	}

	public Map<String, List<Object>> getPropInList() {
		return propInList;
	}

	public void setPropInList(Map<String, List<Object>> propInList) {
		this.propInList = propInList;
	}

	public void addPropInList(String propName, Object... inList) {
		addPropInList(propName, Arrays.asList(inList));
	}

	public void addPropInList(String propName, List<Object> inList) {
		if (null == this.propInList) {
			this.propInList = Maps.newHashMap();
		}
		if (this.propInList.containsKey(propName)) {
			List<Object> il = this.propInList.get(propName);
			il.addAll(inList);
			this.propInList.put(propName, il);
		} else {
			this.propInList.put(propName, inList);
		}

	}
}
